package cn.ds.assets.module.assets.dal.mysql.metadataModelManage;

import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDate;

import cn.ds.assets.framework.common.pojo.PageResult;
import cn.ds.assets.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ds.assets.framework.mybatis.core.mapper.BaseMapperX;
import cn.ds.assets.module.assets.dal.dataobject.metadataModelManage.BaseMetadataModelManageDO;
import org.apache.ibatis.annotations.Mapper;
import cn.ds.assets.module.assets.controller.admin.metadataModelManage.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 元数据管理-元模型-管理属性 Mapper
 *
 * @author admin
 */
@Mapper
public interface BaseMetadataModelManageMapper extends BaseMapperX<BaseMetadataModelManageDO> {

    default PageResult<BaseMetadataModelManageDO> selectPage(BaseMetadataModelManagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BaseMetadataModelManageDO>()
                .eqIfPresent(BaseMetadataModelManageDO::getSort, reqVO.getSort())
                .likeIfPresent(BaseMetadataModelManageDO::getAttrName, reqVO.getAttrName())
                .eqIfPresent(BaseMetadataModelManageDO::getAttrDesc, reqVO.getAttrDesc())
                .eqIfPresent(BaseMetadataModelManageDO::getRange, reqVO.getRange())
                .eqIfPresent(BaseMetadataModelManageDO::getRequired, reqVO.getRequired())
                .eqIfPresent(BaseMetadataModelManageDO::getReadOnly, reqVO.getReadOnly())
                .eqIfPresent(BaseMetadataModelManageDO::getCreateBy, reqVO.getCreateBy())
                .betweenIfPresent(BaseMetadataModelManageDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseMetadataModelManageDO::getUpdateBy, reqVO.getUpdateBy())
                .eqIfPresent(BaseMetadataModelManageDO::getModelId, reqVO.getModelId())
                .eqIfPresent(BaseMetadataModelManageDO::getModuleType, reqVO.getModuleType())
                .inIfPresent(BaseMetadataModelManageDO::getId,reqVO.getIds())
                .orderByDesc(BaseMetadataModelManageDO::getId));
    }

    default List<BaseMetadataModelManageDO> selectList(BaseMetadataModelManageExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BaseMetadataModelManageDO>()
                .eqIfPresent(BaseMetadataModelManageDO::getSort, reqVO.getSort())
                .likeIfPresent(BaseMetadataModelManageDO::getAttrName, reqVO.getAttrName())
                .eqIfPresent(BaseMetadataModelManageDO::getAttrDesc, reqVO.getAttrDesc())
                .eqIfPresent(BaseMetadataModelManageDO::getRange, reqVO.getRange())
                .eqIfPresent(BaseMetadataModelManageDO::getRequired, reqVO.getRequired())
                .eqIfPresent(BaseMetadataModelManageDO::getReadOnly, reqVO.getReadOnly())
                .eqIfPresent(BaseMetadataModelManageDO::getCreateBy, reqVO.getCreateBy())
                .betweenIfPresent(BaseMetadataModelManageDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseMetadataModelManageDO::getUpdateBy, reqVO.getUpdateBy())
                .eqIfPresent(BaseMetadataModelManageDO::getModelId, reqVO.getModelId())
                .eqIfPresent(BaseMetadataModelManageDO::getModuleType, reqVO.getModuleType())
                .inIfPresent(BaseMetadataModelManageDO::getId,reqVO.getIds())
                .orderByDesc(BaseMetadataModelManageDO::getId));
    }

    @Update("UPDATE assets_metadata_model_manage SET deleted = 1, update_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
}
